import 'package:casdon/core/logger/log.dart';
import 'package:casdon/core/network/business_exception.dart';
import 'package:casdon/modules/lifeCircle/data/api/life_topic_comment_list_api.dart';
import 'package:casdon/modules/lifeCircle/data/repository/life_repository.dart';

class LifeTopicCommentListUsecase {
  final LifeRepository _repository;

  const LifeTopicCommentListUsecase(this._repository);

  Future<ResponseLifeTopicCommentListApi> execute({
    required String topicId,
    required int pageNum,
    required int pageSize,
  }) async {
    try {
      final res = await _repository.getTopicComments(
        topicId: topicId,
        pageNum: pageNum,
        pageSize: pageSize,
      );
      return res ?? ResponseLifeTopicCommentListApi(0, const []);
    } on BusinessException {
      rethrow;
    } catch (e, stack) {
      Log.e('LifeTopicCommentListUsecase 失败', e.toString(), stack);
      throw Exception('LifeTopicCommentListUsecase 失败');
    }
  }
}
